import java.awt.Dimension;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.geom.Point2D;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

public abstract class LabelInput extends JTable {
	protected Point2D point;
	
	protected void init(){
        addHideKeyListener();
        setVisible(true);
		requestFocus();
		editCellAt(0, 0);
		changeSelection(0, 0, true, true);
        setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        setRowSelectionAllowed(false);
        setColumnSelectionAllowed(false);

		Dimension dim = getPreferredSize();
		setBounds((int) point.getX(), (int) point.getY(), (int) dim.getWidth(),
				(int) dim.getHeight());

	}

    protected void addHideKeyListener() {
        addKeyListener(new KeyListener() {
            @Override
            public void keyTyped(KeyEvent keyEvent) {
            }

            @Override
            public void keyPressed(KeyEvent keyEvent) {
            }

            @Override
            public void keyReleased(KeyEvent keyEvent) {
                switch(keyEvent.getKeyCode()) {
                    case KeyEvent.VK_ENTER:
                        write();
                        setVisible(false);
                        break;
                    case KeyEvent.VK_ESCAPE:
                        setVisible(false);
                        break;
                }
            }
        });
    }
    
	protected abstract void write();
}
